package com.abc.robot01.retrofit

import okhttp3.OkHttpClient
import okhttp3.RequestBody
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path
import java.util.concurrent.TimeUnit

interface UploadFileService {
    @POST("/abc/def")
    suspend fun uploadFile(
        @Body body: RequestBody
    ):  String

    @GET("/abc/a01/{user}")
    suspend fun a01(
        @Path("user") user:String): String

    companion object {
        private val client by lazy {
            OkHttpClient.Builder()
//                .addInterceptor(RetryInterceptor())
                .connectTimeout(10, TimeUnit.SECONDS)
                .readTimeout(10, TimeUnit.SECONDS)
                .writeTimeout(10, TimeUnit.SECONDS)
                .build()
        }
        private const val BASE_URL =  "https://api.abc.cn/"
        private val retrofit : Retrofit by lazy {
            Retrofit.Builder()
                .baseUrl(BASE_URL)
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .build()}
        val instance: UploadFileService by lazy {
            retrofit.create(UploadFileService::class.java)
        }
    }



}

